﻿namespace Services
{
    /// <summary>
    /// ServiceBase service class that all serivices inherit from
    /// </summary>
    /// <typeparam name="T">The type of provider that the service uses</typeparam>
    public abstract class ServiceBase<T>
    {
        /// <summary>
        /// An instance of the provider this service uses
        /// </summary>
        public T Provider
        {
            get;
            protected set;
        }

        /// <summary>
        /// Return whether this service is connected to a valid provider
        /// </summary>
        public bool IsConnected
        {
            get
            {
                return (Provider != null);
            }
        }

        /// <summary>
        /// Create a provider of the type used by the service
        /// </summary>
        /// <returns>A provider</returns>
        protected abstract T CreateProvider();

        /// <summary>
        /// Initialise the base class
        /// </summary>
        protected void Initialise()
        {
            Provider = CreateProvider();
        }
    }
}